JsBlobRandomAccessSource

JavaScript/Browser implementation of RandomAccessSource using Blob API.

Uses Blob.slice() for efficient random access to file data without loading the entire file into memory.

Important: Browser Blob operations are inherently asynchronous. This implementation pre-loads metadata section during open for synchronous access via readAt, and provides readAtAsync for accessing data beyond the preloaded buffer.

Usage:

// From file input
val file: File = document.getElementById("fileInput").files[0]
val source = JsBlobRandomAccessSource.open(file)

// Sync access for metadata (within preloaded buffer)
val header = source.readAt(0, 24)

// Async access for tensor data
val tensorData = source.readAtAsync(tensorOffset, tensorSize)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The size of the preloaded buffer in bytes. Reads within this range are synchronous.

Link copied to clipboard
open override val size: Long

The total size of the source in bytes.

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
open override fun readAt(position: Long, length: Int): ByteArray

Read bytes from the specified position.

open override fun readAt(position: Long, buffer: ByteArray, offset: Int, length: Int): Int

Read bytes into an existing buffer.

Link copied to clipboard
suspend fun readAtAsync(position: Long, length: Int): ByteArray

Asynchronously read bytes from any position.